<!DOCTYPE html>
<body>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id="log"></div>
<textarea></textarea>
<script>
test(function() {
    var textarea = document.querySelector('textarea');
    textarea.focus();
    eventSender.keyDown('H');
    eventSender.keyDown('Enter');
    eventSender.keyDown('W');
    assert_equals(textarea.value, 'H\nW');
    textarea.setSelectionRange(2, 3); // "W"
    document.execCommand('cut');
    assert_equals(textarea.value, 'H\n');
    textarea.setSelectionRange(0, 0);
    document.execCommand('paste');
    assert_equals(textarea.value, 'WH\n');
}, 'TEXTAREA should not remove the last EOL on paste.');

test(function() {
    var textarea1 = document.createElement('textarea');
    document.body.appendChild(textarea1);
    textarea1.focus();
    textarea1.addEventListener('copy', function(event) {
        event.clipboardData.setData('text', 'foo\n');
        event.preventDefault();
    });
    document.execCommand('copy');

    // Use another TEXAREA.  We need a clean one.
    var textarea2 = document.createElement('textarea');
    document.body.appendChild(textarea2);
    textarea2.focus();
    document.execCommand('paste');
    assert_equals(textarea2.value, 'foo\n');
}, 'Pasting text ending \\n should not add another \\n.');

test(function() {
    var textarea = document.createElement('textarea');
    document.body.appendChild(textarea);
    textarea.focus();
    document.execCommand('InsertLineBreak');
    assert_equals(textarea.value, '\n');
}, 'InsertLineBreak command should insert just one newline.');
</script>
</body>
